1. Technical Field
The present invention relates generally to an improved data processing system and in particular to a method and apparatus for locking objects with high concurrency. Still more particularly, the present invention provides a method and apparatus for locking objects in a Java virtual machine with high concurrency.
2. Description of Related Art
Java(trademark) is an object oriented programming language and environment focusing on defining data as objects and the methods that may be applied to those objects. Java supports only a single inheritance, meaning that each class can inherit from only one other class at any given time. Java also allows for the creation of totally abstract classes known as interfaces, which allow the defining of methods that may be shared with several classes without regard for how other classes are handling the methods. Java provides a mechanism to distribute software and extends the capabilities of a Web browser because programmers can write an applet once and the applet can be run on any Java enabled machine on the Web.
The Java virtual machine (JVM) is a virtual computer component that resides only in memory. The JVM allows Java programs to be executed on different platforms as opposed to only the one platform for which the code was compiled. Java programs are compiled for the JVM. In this manner Java is able to support applications for many types of data processing systems, which may contain a variety of central processing units and operating systems architectures. To enable a Java application to execute on different types of data processing systems, a compiler typically generates an architecture-neutral file formatxe2x80x94the compiled code is executable on many processors, given the presence of the Java run time system. The Java compiler generates bytecode instructions that are non-specific to particular computer architectures. A bytecode is a machine independent code generated by the Java compiler and executed by a Java interpreter. A Java interpreter is a module in the JVM that alternatively decodes and executes a bytecode or bytecodes. These bytecode instructions are designed to be easy to interpret on any machine and easily translated on the fly into native machine code.
A development environment, such as the Java Development Kit (JDK) available from Sun Microsystems, Inc., may be used to build Java bytecode from Java language source code and libraries. This Java bytecode may be stored as a Java application or applet on a Web Server, where it can be downloaded over a network to a user""s machine and executed on a local JVM.
A mutex is the thing that is locked. A lock is the state of holding the mutex. Locking is the act of getting a lock on the mutex.
Each object in a JVM is associated with a xe2x80x9cmutexxe2x80x9d for locking. This locking is used to coordinate multi-threaded access to an object. With respect to accessing objects in a JVM, Java has limitations on how objects are locked. In particular, synchronization blocks are employed to lock objects instead of explicit locking and unlocking of objects. This implies that a lock must be obtained and released in a contiguous block of code. Also, within Java a mechanism is absent to see if an object is locked. This implies that the only way to see if an object is locked it to lock it. Existing high concurrency mechanisms (e.g. cache managers) are implemented without these restrictions. Therefore, it would be advantageous to have a method and apparatus for providing high-concurrency locking mechanism for objects in a Java environment.
The present invention provides a method and apparatus in a data processing system for managing access to objects (called an element) in a collection of objects (called a container) in a high-concurrency environment. A request is received from a requester for an element""s mutex given an identifier for the element. This mutex can be used as a mutex in a synchronized block to lock the object during that synchronized block.
To compute the mutex for an element, the first instance seen by the container of the element""s identifier is used. To do this, a determination is made as to whether there is already an instance of the identifier with the same value in a value set. If so, that value is returned to the requester for use as a mutex. If not, the current identifier instance is saved in the value set and returned. This allows the object to be locked prior to the existence of the object.